package com.ulook.lookplanet.main;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import com.ulook.lookplanet.data.repository.MainRepository;
import com.ulook.lookplanet.data.source.MainDataSource;


/**
 * 描述：
 *
 * @author L1998
 * @data 2021/3/26
 */
public class MainViewModeFactory implements ViewModelProvider.Factory{

    private Application application;

    public MainViewModeFactory(){
        this.application = null;
    }

    public MainViewModeFactory(Application application){
        this.application = application;
    }
    /**
     * Creates a new instance of the given {@code Class}.
     * <p>
     *
     * @param modelClass a {@code Class} whose instance is requested
     * @return a newly created ViewModel
     */
    @NonNull
    @Override
    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
        if (modelClass.isAssignableFrom(MainViewModel.class)) {
            MainViewModel viewModel = new MainViewModel( application, MainRepository.getInstance(new MainDataSource()));
            return (T) viewModel;
        } else {
            throw new IllegalArgumentException("Unknown ViewModel class");
        }
    }
}
